package com.Spring.SpringSpms.config;

import javax.sql.DataSource;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

import com.Spring.SpringSpms.dao.*;

@Configuration
@ComponentScan(basePackages="com.Spring.SpringSpms")
@EnableWebMvc
public class MvcConfiguration extends WebMvcConfigurerAdapter{

	@Bean
	public ViewResolver getViewResolver(){
		InternalResourceViewResolver resolver = new InternalResourceViewResolver();
		resolver.setPrefix("/WEB-INF/views/");
		resolver.setSuffix(".jsp");
		return resolver;
	}
	
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
	}


	@Bean
	public DataSource getDataSource() {
		DriverManagerDataSource dataSource = new DriverManagerDataSource();
		dataSource.setDriverClassName("com.mysql.jdbc.Driver");
		dataSource.setUrl("jdbc:mysql://localhost:3306/springct");
		dataSource.setUsername("root");
		dataSource.setPassword("dhanashree");
		
		return dataSource;
	}
	
	@Bean
	public StatusDAO getStatusDAO() {
		return new StatusDAOImpl(getDataSource());
		
	}


	@Bean
	public PriorityDAO getPriorityDAO() {
		return new PriorityDAOImpl(getDataSource());
		
	}

	
	@Bean
	public ComplexityDAO getComplexityDAO() {
		return new ComplexityDAOImpl(getDataSource());
		
	}


	@Bean
	public DesignationDAO getDesignationDAO() {
		return new DesignationDAOImpl(getDataSource());
		
	}

	@Bean
	public PlatFormDAO getPlatFormDAO() {
		return new PlatFormDAOImpl(getDataSource());
		
	}

	@Bean
	public RoleDAO getRoleDAO() {
		return new RoleDAOImpl(getDataSource());
		
	}


	@Bean
	public StoryPointsDAO getStoryPointsDAO() {
		return new StoryPointsDAOImpl(getDataSource());
		
	}

	@Bean
	public StoryDAO getStoryDAO() {
		return new StoryDAOImpl(getDataSource());
		
	}
	@Bean
	public SprintPlanningDAO getSprintPlanningDAO()
	{
		return new SprintPlanningDAOImpl(getDataSource());
	}
	@Bean
	public ProjectDAO getProjectDAO()
	{
		return new ProjectDAOImpl(getDataSource());
	}
	
	@Bean
	public TaskDAO getTaskDAO() {
		return new TaskDAOImpl(getDataSource());
	}
	
	@Bean
	public EmployeeDAO getEmployeeDAO() {
		return new EmployeeDAOImpl(getDataSource());
	}
	
	@Bean
	public ClientDAO getClientDAO() {
		return new ClientDAOImpl(getDataSource());
	}
		
}
